package com.baozun.houji.me.viewmodel

import androidx.lifecycle.MutableLiveData
import com.baozhun.mall.common.model.bean.UserInfo
import com.baozhun.mall.common.model.request.UpdateUserInfoReqBean
import com.baozhun.mall.common.network.mCommonApiService
import com.baozun.houji.me.model.request.NotifyStatusReqBean
import com.baozun.houji.me.network.mMeApiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.requestNoCheck

/**
 * @Title：
 * @Description：
 * @Author：xing.luo
 * @Since：2022/11/17
 * @Version：1.0.0
 */
class SetViewModel : BaseViewModel() {

    var mUserInfo = MutableLiveData<UserInfo>()
    var mCacheSize = MutableLiveData<String>()


    /**
     * 更新用戶信息
     */
    fun updateUserInfo(responseBack: () -> Unit) {
        var updateUserInfoReqBean =
            UpdateUserInfoReqBean(mUserInfo.value?.nickname, mUserInfo.value?.birthday, mUserInfo.value?.sex, mUserInfo.value?.photo)
        requestNoCheck({ mCommonApiService.updateUserInfo(updateUserInfoReqBean) }, {
            responseBack.invoke()
        }, {
            responseBack.invoke()
        }, isShowDialog = true)
    }

    /**
     * 更新通知状态设置信息
     */
    fun updateNotifyStatus(responseBack: () -> Unit) {
        var notifyStatusReqBean =
            NotifyStatusReqBean(mUserInfo.value?.is_notice, mUserInfo.value?.trans_notice, mUserInfo.value?.refund_notice, mUserInfo.value?.expire_notice,mUserInfo.value?.rebate_notice)
        requestNoCheck({ mMeApiService.updateNotifyStatus(notifyStatusReqBean) }, {
            responseBack.invoke()
        }, {
            responseBack.invoke()
        }, isShowDialog = true)
    }
}